package com.helen.ui;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.widget.ImageView;

import com.helen.db.UserHelper;
import com.helen.shopping.R;
import com.helen.ui.login.LoginActivity;
import com.helen.utils.MyLog;
import com.helen.utils.StatusBarUtil;
import com.tbruyelle.rxpermissions2.RxPermissions;

import butterknife.BindView;
import io.reactivex.functions.Consumer;

/**
 * Created by yang on 2018/4/14.
 * 闪屏页
 */

public class SplashActivity extends BaseActivity {
    @BindView(R.id.iv_splash)
    ImageView ivSplash;
    private Handler mHandler;
    private Runnable mRunnable;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initInjector() {
        UserHelper.getInstance().setIsLogined(initLoginState());
    }

    @Override
    protected void initViews() {
        StatusBarUtil.setTranslucentForImageViewInFragment(SplashActivity.this, null);
        mHandler = new Handler();
        mRunnable = new Runnable() {
            @Override
            public void run() {
                intoMainActivity();
            }
        };
        mHandler.postDelayed(mRunnable, 2000);
    }

    private void intoMainActivity() {
//        if (UserHelper.getInstance().getloginEntity(SplashActivity.this) == null) {
//            startActivity(new Intent(SplashActivity.this, LoginActivity.class));
//        } else {
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
//        }
        overridePendingTransition(R.anim.hold, R.anim.zoom_in_exit);
        finish();
    }

    @Override
    protected void updateViews() {

    }

    //用户是否存在判断
    private boolean initLoginState() {
        if ( UserHelper.getInstance().getloginEntity(this) == null ) {
            return false;
        } else {
            return true;
        }
    }
}
